package com.basic.modules.nykf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.basic.common.utils.ParamsModel;
import com.basic.common.utils.R;
import com.basic.modules.nykf.entity.CustomerShopBusinessEntity;
import com.basic.modules.nykf.entity.ZzhEntity;
import com.basic.modules.nykf.entity.ZzhFpGsEntity;
import com.basic.modules.nykf.entity.ZzhFpKfEntity;
import com.basic.modules.nykf.service.SubAccountService;
import com.basic.modules.nykf.service.ZzhFpGsService;
import com.basic.modules.nykf.service.ZzhFpKfService;
import com.basic.modules.nykf.service.ZzhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

/**
 * 子账号相关
 */
@RestController
@RequestMapping("new/ykf/subAccount")
public class SubAccountController {

    @Autowired
    SubAccountService subAccountService;

    @Autowired
    ZzhService zzhService;

    @Autowired
    ZzhFpGsService zzhFpGsService;

    @Autowired
    ZzhFpKfService zzhFpKfService;

    /**
     * 业务人员使用
     * 子账号管理页面-列表数据
     *
     * @param params
     * @return
     */
    @PostMapping("/getZzhGlList")
    public R getZzhGlList(@RequestBody ParamsModel<Map> params) {
        return R.ok(zzhService.getZzhGlList(params));
    }

    /**
     * 业务人员使用
     * 业务模块-根据业务id获取子账号列表
     *
     * @param customerShopBusinessEntity
     * @return
     */
    @PostMapping("/getZzhListByYwId")
    public R getZzhListByYwId(@RequestBody CustomerShopBusinessEntity customerShopBusinessEntity) {
        QueryWrapper<ZzhEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("customer_shop_business_id", customerShopBusinessEntity.getCustomerShopBusinessId());
        List<ZzhEntity> list = zzhService.list(queryWrapper);
        return R.ok(list);
    }

    /**
     * 业务人员使用
     * 业务模块-操作子账号(新增、修改)
     *
     * @param zzhEntity
     * @return
     */
    @PostMapping("/operateZzhObj")
    public R operateZzhObj(@RequestBody ZzhEntity zzhEntity) {
        return subAccountService.operateZzhObj(zzhEntity);
    }

    /**
     * 客服部使用
     * 获取子账号分配公司页面-数据列表
     *
     * @return
     */
    @PostMapping("/getZzhFpgsList")
    public R getZzhFpgsList(@RequestBody ParamsModel<Map> params) {
        return R.ok(zzhFpGsService.getZzhFpgsList(params));
    }

    /**
     * 子账号分配公司前的绩效数据校验
     * @param zzhFpGsEntity
     * @return
     */
    @PostMapping("/postFpGsJxSjJy")
    public R postFpGsJxSjJy(@RequestBody ZzhFpGsEntity zzhFpGsEntity){
        return zzhFpGsService.postFpGsJxSjJy(zzhFpGsEntity);
    }

    /**
     * 客服部使用
     * 子账号分配公司
     *
     * @param zzhFpGsEntity
     * @return
     */
    @PostMapping("/postZzhFpgs")
    public R postZzhFpgs(@RequestBody ZzhFpGsEntity zzhFpGsEntity) {
        return zzhFpGsService.postZzhFpgs(zzhFpGsEntity);
    }

    /**
     * 分公司使用
     * 获取子账号分配客服页面-数据列表
     *
     * @return
     */
    @PostMapping("/getZzhFpkfList")
    public R getZzhFpkfList(@RequestBody ParamsModel<Map> params) {
        return R.ok(zzhFpKfService.getZzhFpkfList(params));
    }

    /**
     * 分公司使用
     * 根据分公司id获取客服列表
     *
     * @param map
     * @return
     */
    @PostMapping("/getKfList")
    public R getKfList(@RequestBody Map map) {
        return R.ok(zzhFpKfService.getKfList(map));
    }

    /**
     * 分公司使用
     * 子账号分配客服
     *
     * @param zzhFpKfEntity
     * @return
     */
    @PostMapping("/postZzhFpkf")
    public R postZzhFpkf(@RequestBody ZzhFpKfEntity zzhFpKfEntity) {
        return zzhFpKfService.postZzhFpkf(zzhFpKfEntity);
    }

    /**
     * 业务部使用
     * 停用子账号
     *
     * @param map
     * @return
     */
    @PostMapping("/postZzhStop")
    public R postZzhStop(@RequestBody Map map) {
        return zzhService.postZzhStop(map);
    }

    /**
     * 业务部使用
     * 启用子账号
     *
     * @param map
     * @return
     */
    @PostMapping("/postZzhEnable")
    public R postZzhEnable(@RequestBody Map map) {
        return zzhService.postZzhEnable(map);
    }

    /**
     * 客服部使用
     * 撤销分配公司
     * @param zzhFpGsEntity
     * @return
     */
    @PostMapping("/postFpgsRevoke")
    public R postFpgsRevoke(@RequestBody ZzhFpGsEntity zzhFpGsEntity){
        return zzhFpGsService.postFpgsRevoke(zzhFpGsEntity);
    }

    /**
     * 分公司使用
     * 撤销分配客服
     * @param zzhFpKfEntity
     * @return
     */
    @PostMapping("/postFpkfRevoke")
    public R postFpkfRevoke(@RequestBody ZzhFpKfEntity zzhFpKfEntity){
        return zzhFpKfService.postFpkfRevoke(zzhFpKfEntity);
    }
}